#ifndef DECODER_H
#define DECODER_H

#include "PacketQueue.h"
#include "SpdLog.h"

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
#include "libavutil/avutil.h"
}

class Decoder
{
public:
	typedef enum MediaType{
		MEDIA_TYPE_UNKNOWN = -1,  ///< Usually treated as AVMEDIA_TYPE_DATA
		MEDIA_TYPE_VIDEO,
		MEDIA_TYPE_AUDIO,
		MEDIA_TYPE_DATA,          ///< Opaque data information usually continuous
		MEDIA_TYPE_SUBTITLE,
		MEDIA_TYPE_ATTACHMENT,    ///< Opaque data information usually sparse
		MEDIA_TYPE_NB
	}MediaType;

	Decoder(AVFormatContext *ic, MediaType type, int stream, PacketQueue *pkt_queue);
	virtual ~Decoder();
	virtual int open();
	virtual void close();
	virtual int decode(AVFrame *frame);
	virtual void flush(){ };
	//void setPktPending(bool pending){m_PktPending = pending;}


	MediaType m_MediaType;
	AVFormatContext *m_Ic;
    AVCodecContext *m_Avctx;
    AVCodec *m_Codec;
    PacketQueue *m_PacketQueue;
    int m_Stream;
    bool m_PktPending;
};

// class VideoDecoder : public Decoder
// {
// public:
// 	VideoDecoder();
// 	virtual ~VideoDecoder(AVFormatContext *ic);
// 	// registerDecoderCallBack();

// 	virtual int open();
// 	virtual void close();

// 	/*true: got a frame else no frame got*/
// 	virtual int decode(AVPacket &pkt, AVFrame &frame);

// public:

// };

// class AudioDecoder : public Decoder
// {
// public:
// 	AudioDecoder(AVFormatContext *ic);
// 	virtual ~AudioDecoder();
// 	// registerDecoderCallBack();

// 	virtual int open();
// 	virtual void close();

// 	/*true: got a frame else no frame got*/
// 	virtual int decode(AVPacket &pkt, AVFrame &frame);

// public:

// };

#endif